<template>
  <div class="news">
    <ul>
      <li v-for="(news, index) in newsList" :key="news.id">
        <!-- 第一种Query传参 -->
        <!-- <RouterLink :to="`/news/detail?id=${news.id}&title=${news.title}&content=${news.content}`">{{ news.title }}
        </RouterLink> -->

        <!-- 第二种Query传参 -->
        <!-- <RouterLink :to="{
          // path: '/news/detail',
          name: 'detailName',
          query: {
            id: news.id,
            title: news.title,
            content: news.content,
          }
        }">
          {{ news.title }}
        </RouterLink> -->

        <!-- 第一种Params传参 -->
        <!-- <RouterLink :to="`/news/detail/${news.id}/${news.title}/${news.content}`">{{ news.title }}
        </RouterLink> -->

        <!-- 第二种Params传参(只能使用name，不能使用path) -->
        <!-- <RouterLink :to="{
          name: 'detailName',
          params: {
            id: news.id,
            title: news.title,
            content: news.content,
          }
        }">
          {{ news.title }}
        </RouterLink> -->

        <!-- 第一种Props传参(与Params传参一样，只能使用name，不能使用path) -->
        <RouterLink :to="{
          name: 'detailName',
          params: {
            id: news.id,
            title: news.title,
            content: news.content,
          }
        }">
          {{ news.title }}
        </RouterLink>
        <button @click="showDetail(news)">查看</button>
      </li>
    </ul>
    <div class="news-content">
      <RouterView></RouterView>
    </div>
  </div>
</template>
<script setup lang="ts" name="News">
import { reactive } from 'vue';
import { RouterLink, RouterView, useRouter } from 'vue-router';
const router = useRouter()

const newsList = reactive([
  { id: 1, title: "很好的食物", content: "西蓝花" },
  { id: 2, title: "如何一夜暴富", content: "学IT" },
  { id: 3, title: "震惊，万万没想到", content: "明天是周一" },
  { id: 4, title: "好消息！好消息", content: "快过年了" },
])

interface INews {
  id: number,
  title: string,
  content: string,
}
function showDetail(news: INews) {
  router.push({
    name: 'detailName',
    params: {
      id: news.id,
      title: news.title,
      content: news.content,
    }
  })
}
</script>
<style scoped>
.news {
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  height: 100%;
}

.news button {
  margin-left: 10px;
}

.news ul {
  margin-top: 30px;
  padding-left: 10px;
}

.news li::marker {
  color: #64967E;
}


.news li>a {
  font-size: 18px;
  line-height: 40px;
  text-decoration: none;
  color: #64967E;
  text-shadow: 0 0 1px rgb(0, 84, 0);
}

.news li.active {
  color: red;
}

.news-content {
  width: 70%;
  height: 90%;
  border: 1px solid;
  margin-top: 20px;
  border-radius: 10px;
}
</style>